<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="UTF-8">
    <title>酒店管理系统主页</title>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <!--<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>-->
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body class="index-body">
<input type="hidden" id="userName" th:value="${session.UserName}"/>
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<input type="hidden" id="UserType" th:value="${session.UserType}"/>
<script type="text/javascript">
    var uname = $('#userName').val();
    var ustatusid = $('#UserStatusid').val();
    if(uname == ''){
        window.location.href = "toLogin.do";
    }
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
    var UserType = $('#UserType').val();
    if(UserType === '经理'){
        window.location.href = "toStatement.do";
    }
</script>
<div class="index">
    <ul class="index-img">
        <li><a href="toReserve.do" class="yuding"><span>预定管理</span></a></li>
        <li><a href="toCheck.do"><span>入住管理</span></a></li>
        <li><a href="toGuestroom.do" class="binke"><span>宾客要求管理</span></a></li>
        <li><a href="toRoomstatus.do"><span>客房管理</span></a></li>
        <li><a href="toVip.do"><span>会员管理</span></a></li>
        <li><a href="toStatement.do"><span>报表管理</span></a></li>
        <li><a href="toDecode.do" class="trivial-system"><span>锁定屏幕</span></a></li>
        <li><a href="toQuit.do"><span>退出系统</span></a></li>
        <li class="admin"><span>欢迎管理员:</span><span th:text="${session.UserName}"></span></li>
    </ul>
</div>
<div class="room">
    <div class="room-type">
        <ul>
            <li><a href="javascript:;" onclick="SingleRoom()">单人间</a></li>
            <li><a href="javascript:;" onclick="StandardRoom()">标准间</a></li>
            <li><a href="javascript:;" onclick="DoubleRoom()">双人间</a></li>
            <li><a href="javascript:;" onclick="DeluxeSuite()">豪华套房</a></li>
            <li><a href="javascript:;" onclick="PresidentialSuite()">总统套房</a></li>
        </ul>
    </div>
    <div class="detail">
        <div class="room-detail">
            <table>
                <thead>
                    <tr>
                        <td width="60px">房号</td>
                        <td width="100px">姓名</td>
                        <td width="100px">房间类型</td>
                        <td width="100px">房间状态</td>
                        <td width="100px">预定时间</td>
                        <td width="100px">到期时间</td>
                        <td width="100px">入住时间</td>
                        <td width="100px">退房时间</td>
                        <td width="200px">备注</td>
                    </tr>
                </thead>
                <tbody id="roomTbody">

                </tbody>
            </table>
            <div class="room-center">
                <ul class="pagination" id="rpage">

                </ul>
                共<span id="rtotalPage"></span>页
            </div>
        </div>
        <div class="consume-detail">
            <table>
                <thead>
                    <tr>
                        <td width="60px">房号</td>
                        <td width="100px">商品名称</td>
                        <td width="100px">商品单价</td>
                        <td width="100px">打折比例</td>
                        <!--<td width="100px">打折单价</td>-->
                        <td width="100px">消费数量</td>
                        <td width="100px">消费总金</td>
                        <td width="100px">消费时间</td>
                    </tr>
                </thead>
                <tbody id="consumeTbody">

                </tbody>
            </table>
            <div class="consume-center">
                <ul class="pagination" id="cpage">

                </ul>
                共<span id="ctotalPage"></span>页
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var singleroom;
    var standardroom;
    var doubleroom;
    var deluxesuite;
    var presidentialsuite;
    findByPage1(1);
    function findByPage1(page){
        $('#roomTbody').empty();
        var currentPage = page;
        $.post(
            "indexList.do",
            {'currentPage': currentPage,'singleroom':singleroom,'standardroom':standardroom,'doubleroom':doubleroom,'deluxesuite':deluxesuite,'presidentialsuite':presidentialsuite},
            function (data){
                if (data.status == 0){
                    var pageBean = data.result;
                    var totalPage = pageBean.totalPage;
                    var RoomstatusList = pageBean.lists;
                    var no = pageBean.pageSize * (currentPage - 1);
                    for (var i = 0;i<RoomstatusList.length;i++){
                        $('#roomTbody').append('<tr>' +
                            '<input type="hidden" value="'+RoomstatusList[i].roomRemark+'"/>'+
                            '<td width="60px">'+RoomstatusList[i].roomId+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomName+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomType+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomState+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomReserve+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomExpire+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomIn+'</td>'+
                            '<td width="100px">'+RoomstatusList[i].roomOut+'</td>'+
                            '<td width="200px">'+'<a href="javascript:;" onclick="roomdetail(this)">查看详情</a>'+'</td>'+
                            '</tr>');
                    }
                    $('#rpage').empty();
                    var begin = 1;
                    var end = 1;
                    if (totalPage <= 5) {
                        begin = 1;
                        end = totalPage;
                    } else {
                        begin = currentPage - 2;
                        end = currentPage + 2;
                        if (begin <= 1) {
                            begin = 1;
                            end = 5;
                        }
                        if (end >= totalPage) {
                            begin = totalPage - 4;
                            end = totalPage;
                        }
                    }
                    //添加上一页的按钮
                    $('#rpage').append('<li id="left" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage1(' + (currentPage - 1) + ')" >&laquo;</span></li>');
                    //添加中间的页数
                    for (var i = begin; i <= end; i++) {
                        $('#rpage').append('<li class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><a onclick="findByPage1(' + i + ')">' + i + '</a></li>');
                    }
                    //添加下一页的按钮
                    $('#rpage').append('<li id="right" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage1(' + (currentPage + 1) + ')" >&raquo;</span></li>');
                    if (currentPage == 1) {
                        //添加禁用样式
                        $('#left').addClass('disabled');
                        //清除点击事件
                        $('#left>span').removeAttr('onclick');
                    }
                    if (currentPage == totalPage) {
                        //添加禁用样式
                        $('#right').addClass('disabled');
                        //清除点击事件
                        $('#right>span').removeAttr('onclick');
                    }
                    //添加当前页的激活样式
                    $('#rpage>li').eq(currentPage - begin + 1).addClass('selectPage');
                    //显示总页数
                    $('#rtotalPage').html(totalPage);
                }else{
                    layer.msg(data.message);
                }
            }
        );
    }
    function roomdetail(btn) {
        var $tds = $(btn).parent().siblings();
        var roomremark = $($tds[0]).val();
        layer.alert(roomremark);
    }
    findByPage(1);
    function findByPage(page){
        $('#consumeTbody').empty();
        var currentPage = page;
        $.post(
            "indexConsumeList.do",
            {'currentPage': currentPage},
            function (data){
                if (data.status == 0){
                    var pageBean = data.result;
                    var totalPage = pageBean.totalPage;
                    var guestroomConsumeList = pageBean.lists;
                    var no = pageBean.pageSize * (currentPage - 1);
                    for (var i = 0;i<guestroomConsumeList.length;i++){
                        $('#consumeTbody').append('<tr>' +
                            '<td width="60px">'+guestroomConsumeList[i].consumeRoomid+'</td>'+
                            '<td width="100px">'+guestroomConsumeList[i].consumeName+'</td>'+
                            '<td width="100px">'+guestroomConsumeList[i].consumePrice+'</td>'+
                            '<td width="100px">'+guestroomConsumeList[i].vip.vipDiscount+'</td>'+
                            '<td width="100px">'+guestroomConsumeList[i].consumeNumber+'</td>'+
                            '<td width="100px">'+(guestroomConsumeList[i].consumePrice*guestroomConsumeList[i].consumeNumber*guestroomConsumeList[i].vip.vipDisDouble)+'</td>'+
                            '<td width="100px">'+guestroomConsumeList[i].consumeTime+'</td>'+
                            '</tr>');
                    }
                    $('#cpage').empty();
                    var begin = 1;
                    var end = 1;
                    if (totalPage <= 5) {
                        begin = 1;
                        end = totalPage;
                    } else {
                        begin = currentPage - 2;
                        end = currentPage + 2;
                        if (begin <= 1) {
                            begin = 1;
                            end = 5;
                        }
                        if (end >= totalPage) {
                            begin = totalPage - 4;
                            end = totalPage;
                        }
                    }
                    //添加上一页的按钮
                    $('#cpage').append('<li id="left" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage - 1) + ')" >&laquo;</span></li>');
                    //添加中间的页数
                    for (var i = begin; i <= end; i++) {
                        $('#cpage').append('<li class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><a onclick="findByPage(' + i + ')">' + i + '</a></li>');
                    }
                    //添加下一页的按钮
                    $('#cpage').append('<li id="right" class="" style="display: inline-block;border: 1px solid blue;width: 20px;height: 20px"><span onclick="findByPage(' + (currentPage + 1) + ')" >&raquo;</span></li>');
                    if (currentPage == 1) {
                        //添加禁用样式
                        $('#left').addClass('disabled');
                        //清除点击事件
                        $('#left>span').removeAttr('onclick');
                    }
                    if (currentPage == totalPage) {
                        //添加禁用样式
                        $('#right').addClass('disabled');
                        //清除点击事件
                        $('#right>span').removeAttr('onclick');
                    }
                    //添加当前页的激活样式
                    $('#cpage>li').eq(currentPage - begin + 1).addClass('selectPage');
                    //显示总页数
                    $('#ctotalPage').html(totalPage);
                }else {
                    layer.msg(data.message);
                }
            }
        );
    }
    function SingleRoom() {
        singleroom = "单人间";
        standardroom = "";
        doubleroom = "";
        deluxesuite = "";
        presidentialsuite = "";
        findByPage1(1);
    }
    function StandardRoom() {
        standardroom = "标准间";
        singleroom = "";
        doubleroom = "";
        deluxesuite = "";
        presidentialsuite = "";
        findByPage1(1);
    }
    function DoubleRoom() {
        doubleroom = "双人间";
        standardroom = "";
        singleroom = "";
        deluxesuite = "";
        presidentialsuite = "";
        findByPage1(1);
    }
    function DeluxeSuite() {
        deluxesuite = "豪华套房";
        doubleroom = "";
        standardroom = "";
        singleroom = "";
        presidentialsuite = "";
        findByPage1(1);
    }
    function PresidentialSuite() {
        presidentialsuite = "总统套房";
        deluxesuite = "";
        doubleroom = "";
        standardroom = "";
        singleroom = "";
        findByPage1(1);
    }
</script>
</html>
